using System;
using System.Collections.Generic;
using System.Linq;

namespace Common
{
	/// <summary>
	/// 
	/// </summary>
	[Serializable]
	public class Curve
	{
		private List<Dot> _CurvePoint = new List<Dot>();

		public List<Dot> CurvePoint
		{
			get
			{
				return _CurvePoint;
			}
			set
			{
				if (_CurvePoint != value)
				{
					_CurvePoint = value;
				}
			}
		}

		public double GetCurveMinX()
		{
			return GetCurveMinMaxXY(true, true);
		}

		public double GetCurveMaxX()
		{
			return GetCurveMinMaxXY(true, false);
		}

		public double GetCurveMinY()
		{
			return GetCurveMinMaxXY(false, true);
		}

		public double GetCurveMaxY()
		{
			return GetCurveMinMaxXY(false, false);
		}

		public double GetCurveMinMaxXY(bool x, bool min)
		{
			double result = double.NaN;
			if (CurvePoint.Count != 0)
			{
				if (x)
				{
					if (min)
					{
						return CurvePoint.Select((Dot s) => s.X).Min();
					}
					return CurvePoint.Select((Dot s) => s.X).Max();
				}
				if (min)
				{
					return CurvePoint.Select((Dot s) => s.Y).Min();
				}
				return CurvePoint.Select((Dot s) => s.Y).Max();
			}
			return result;
		}
	}
}
